import requests,json
from lxml import etree


url='https://www.lmonkey.com/essence'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
}
res=requests.get(url=url,headers=headers)

if res.status_code==200:
    with open('./yz.html','w',encoding='utf-8') as fp:
        fp.write(res.text)

html=etree.parse('./yz.html',parser=etree.HTMLParser())
titles=html.xpath('//div[@class="flex-fill  col-12 col-md-8 px-3 px-md-0 pt-2 pt-md-0"]//div[@class="topic_title mb-0  essence_title yh"]/text()')
urls=html.xpath('//div[@class="flex-fill  col-12 col-md-8 px-3 px-md-0 pt-2 pt-md-0"]//p[@class="lh-140 mb-0 topic_info pt-3"]/a/@href')
authors=html.xpath('//div[@class="flex-fill  col-12 col-md-8 px-3 px-md-0 pt-2 pt-md-0"]//p[@class="lh-140 mb-0 topic_info pt-3"]/a/span/text()')
data=[]
for i in range(len(titles)):
    res={'title=':titles[i],'url':urls[i],'author':authors[i]}
    print(res)
    data.append(res)
print(data)

with open('./yq.json','w') as fp:
    json.dump(data,fp)
#lists=zip(urls,titles,authors)
#print(*lists)

